var page = 1;
//引入产品数据
// var dataObj = require('../../graceUI/demoData/data.js');
// var products = dataObj.products;
Page({
  data: {
    loadingType: 0,
    productList: [[], []]
  },
  onLoad: function (options) {
    this.getList();
  },
  //上拉加载更多
  onReachBottom: function () {
    //避免多次触发
    if (this.data.loadingType != 3) { return; }
    this.getList();
  },
  getList: function () {
    //最后一页判断
    if (page > 3) {
      this.setData({ loadingType: 2 });
      return;
    }
    this.setData({ loadingType: 1 });
    //模拟api请求延迟关闭 Loading
    setTimeout(()=>{
      var lArr = this.data.productList[0];
      var rArr = this.data.productList[1];
      //填充数组[此处的 products 数据应该来自与api接口数据]
      //数据格式见 "/data/data.js"
      products = dataObj.getArrRandomly(products); //打乱排序【模拟api】
      for (var i = 0; i < products.length; i++) {
        if (i % 2 == 0) {
          lArr.push(products[i]);
        } else {
          rArr.push(products[i]);
        }
      }
      this.setData({ productList: [lArr, rArr] });
      this.setData({ loadingType: 3 });
      page++;
    }, 1000);
  }
})